<!DOCTYPE html>
<html>
    <head>
        <meta name="layout" content="main" />
        <g:set var="entityName" value="${message(code: 'product.label', default: 'Product')}" />
        <title>产品：${this.product.name}</title>
    </head>
    <body class="fixed-navbar fixed-sidebar">
        <div class="small-header">
            <div class="hpanel">
                <div class="panel-body">
                    <div id="hbreadcrumb" class="pull-right">
                        <ol class="hbreadcrumb breadcrumb">
                            <li>Cake Store</li>
                            <li>
                                <g:link controller="product" action="index">产品管理</g:link>
                            </li>
                            <li class="active">
                                <span>${this.product.name}</span>
                            </li>
                        </ol>
                    </div>

                    <h2 class="font-light m-b-xs" style="text-transform:none;">
                        产品: ${this.product.name}
                    </h2>
                </div>
            </div>
        </div>
        <div class="content animate-panel">
            <div class="row">
                <div class="hpanel hblue">
                    <div class="panel-heading">
                        产品信息编辑
                    </div>
                    <div class="panel-body">
                        <g:form resource="${this.product}" method="PUT" class="form-horizontal" name="myForm">
                            <g:if test="${flash.message}">
                                <div class="message" role="status">${flash.message}</div>
                            </g:if>
                            <g:hasErrors bean="${this.product}">
                                <ul class="errors" role="alert">
                                    <g:eachError bean="${this.product}" var="error">
                                        <li <g:if test="${error in org.springframework.validation.FieldError}">data-field-id="${error.field}"</g:if>>
                                            <g:message error="${error}" />
                                        </li>
                                    </g:eachError>
                                </ul>
                            </g:hasErrors>
                            

                            <div class="form-group">
                                <label class="col-md-3 control-label">产品类型</label>
                                <div class="col-md-3">
                                    <g:select class="form-control m-b" name="type" id="type" optionValue="name" optionKey="id" from="${com.next.ProductType.list()}" value="${this.product?.type?.id}"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-3 control-label">产品名称</label>
                                <div class="col-md-3">
                                    <g:textField name="name" id="name" value="${this.product?.name}" class="form-control" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-3 control-label">单价</label>
                                <div class="col-md-3 input-group">
                                    <g:textField name="price" id="price" value="${this.product?.price}" class="form-control" />
                                    <span class="input-group-addon">元</span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-3 control-label">有效性</label>
                                <div class="col-md-1">
                                    <g:checkBox name="active" id="active" value="${this.product?.active}" class="form-control" style="height:16px;margin-top: 10px"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-3 control-label">描述</label>
                                <div class="col-md-5">
                                    <g:textArea rows="3" class="form-control" name="description" id="description" value="${this.product?.description}" />
                                </div>
                            </div>
                            
                            <div class="form-group">
                                <div class="col-md-3 col-md-offset-3">
                                    <button class="btn btn-info" type="button" style="width:100%" id="click1">保存</button>
                                </div>
                            </div>
                        </g:form>
                    </div>
                </div>
            </div>
        </div>

        <g:javascript>
            $(function () {
                $("#click1").click(function() {

                    var name = $("#name").val().trim();
                    if (!name)
                    {
                        toastr.error('请输入产品名称');
                        return;
                    }

                    var price = $("#price").val().trim();
                    if (!price) {
                        toastr.error('请输入产品单价');
                        return;
                    }

                    if (!(/^[1-9]\d*(\.\d+)?$/.test(price))) {
                        toastr.error('请输入正确的产品单价');
                        return;
                    }

                    $("#myForm").submit();
                });
            });
        </g:javascript>

    </body>
</html>
